package ln.fxspringarchetype.controller;

import javafx.fxml.Initializable;
import javafx.util.Duration;
import org.controlsfx.control.Notifications;

import java.net.URL;
import java.util.ResourceBundle;

/**
 * 所有应用控制器的基类，继承此类，不用每个都去重载初始化的步骤
 */
public abstract class BaseFxController implements Initializable, FxController {
    private URL location;
    private ResourceBundle resoures;

    public URL getLocation() {
        return location;
    }

    public void setLocation(URL location) {
        this.location = location;
    }

    public ResourceBundle getResoures() {
        return resoures;
    }

    public void setResoures(ResourceBundle resoures) {
        this.resoures = resoures;
    }

    /**
     * 控制器组件初始化的子步骤
     *
     * @param location  fxml文件的地址
     * @param resources 资源包
     */
    @Override
    public void initialize(URL location, ResourceBundle resources) {
        setLocation(location);
        setResoures(resources);

        setCellValueFactories();
        setCellFactories();
        createBindings();
        initLayout();
        loadData();
    }

    /**
     * 在屏幕右下角显示操作结果提示框
     *
     * @param title 提示框标题文字
     * @param text  提示框内容文字
     */
    protected Notifications showPrompt(String title, String text) {
        Notifications notifications = Notifications.create();
        notifications.title(title);
        notifications.text(text);
        notifications.hideCloseButton();
        notifications.hideAfter(Duration.seconds(2));
        return notifications;
    }
}
